<template>
  <div class="app-container">
    <div class="filter-container">
      <el-form :inline="true" :model="formModel">
        <el-form-item class="no-warn-item" label="工厂:" prop="plantNo">
          <el-select v-model="formModel.plantNo" clearable filterable>
            <el-option v-for="item in plantOptions" :key="item.tmBasPlantId" :label="item.plantNameC" :value="item.plantNo" />
          </el-select>
        </el-form-item>
        <el-form-item class="no-warn-item" label="计划编号:" prop="planNo">
          <el-input
            v-model="formModel.planNo"
            class="filter-item "
            clearable
          />
        </el-form-item>
        <el-form-item class="no-warn-item" label="订单编号:" prop="orderId">
          <el-input
            v-model="formModel.orderId"
            class="filter-item "
            clearable
          />
        </el-form-item>
        <el-form-item class="no-warn-item" label="车辆VIN号:" prop="vin">
          <el-input
            v-model="formModel.vin"
            class="filter-item "
            clearable
          />
        </el-form-item>
        <el-form-item class="no-warn-item" label="整车物料号:" prop="materialNo">
          <el-input v-model="formModel.materialNo" disabled>
            <el-button slot="append" type="primary" icon="el-icon-search" @click="queryMaterialData" />
          </el-input>
        </el-form-item>
        <el-form-item class="no-warn-item" label="订单状态:" prop="orderStatus">
          <hey-select v-model="formModel.orderStatus" clcd="order_status_cd" />
        </el-form-item>
        <el-row class="submit-area">
          <el-col :span="24">
            <el-button v-if="hasPermission('order_select')" type="primary" plain @click="queryList">查询</el-button>
            <el-button v-if="hasPermission('order_clear')" type="primary" plain @click="clearCondition">清除</el-button>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <h3>订单基本信息列表:</h3>
    <hey-table ref="table" :is-radio="true" :columns="columns" @row-click="handleRowClick">
      <template slot="tools">
        <el-table-column
          label="操作"
          width="80"
          fixed="right"
          header-align="center"
          align="center"
        >
          <template slot-scope="{row}">
            <span v-if="hasPermission('order_edit')" class="hey_tools_btn" @click="handleEdit(row)">编辑</span>
          </template>
        </el-table-column>
      </template>
    </hey-table>
    <h3>订单选配配置列表:</h3>
    <hey-table ref="table1" :table-data="tableData1" :columns="columns1">
      <template slot="tools">
        <el-table-column
          label="操作"
          width="120"
          fixed="right"
          header-align="center"
          align="center"
        >
          <template slot-scope="{row}">
            <span v-if="hasPermission('order_bom_edit')" class="hey_tools_btn" @click="handleEditBom(row)">编辑</span>
            <span v-if="hasPermission('order_bom_delete')" class="hey_tools_btn" @click="handleDeleteBom(row)">删除</span>
          </template>
        </el-table-column>
      </template>
    </hey-table>
    <h3>订单追溯配置列表:</h3>
    <hey-table ref="table2" :table-data="tableData2" :columns="columns2">
      <template slot="tools">
        <el-table-column
          label="操作"
          width="120"
          fixed="right"
          header-align="center"
          align="center"
        >
          <template slot-scope="{row}">
            <span v-if="hasPermission('order_part_track_edit')" class="hey_tools_btn" @click="handleEditPartTrack(row)">编辑</span>
            <span v-if="hasPermission('order_part_track_delete')" class="hey_tools_btn" @click="handleDeletePartTrack(row)">删除</span>
          </template>
        </el-table-column>
      </template>
    </hey-table>
    <h3>订单电检配置列表:</h3>
    <hey-table ref="table3" :table-data="tableData3" :columns="columns3" />
    <el-dialog
      v-if="dialogVisible"
      v-dialogDrag
      :close-on-click-modal="false"
      title="订单基本信息"
      :visible.sync="dialogVisible"
      width="80%"
    >
      <order-control-mnt :page-type="operType" :edit-data="editData" @mntSuc="queryList" />
    </el-dialog>

    <el-dialog
      v-if="showOrderConfigOptional"
      v-dialogDrag
      :close-on-click-modal="false"
      title="订单选配配置"
      :visible.sync="showOrderConfigOptional"
      width="80%"
    >
      <orderConfigOptional-mnt :page-type="operType" :edit-data="editData" @queryOrderConfigOptionalSuc="queryList1" />
    </el-dialog>

    <el-dialog
      v-if="showOrderPartTrack"
      v-dialogDrag
      :close-on-click-modal="false"
      title="订单追溯配置"
      :visible.sync="showOrderPartTrack"
      width="80%"
    >
      <orderPartTrack-mnt :page-type="operType" :edit-data="editData" @queryOrderPartTrackSuc="queryList2" />
    </el-dialog>

    <el-dialog
      v-if="showMaterialData"
      v-dialogDrag
      :close-on-click-modal="false"
      title="物料主数据"
      :visible.sync="showMaterialData"
      width="90%"
      append-to-body
    >
      <material-data-dialog :edit-data="editData" @queryMaterialDataSuc="queryMaterialDataSuc" />
    </el-dialog>
  </div>
</template>

<script>

export default {
  name: 'OrderControllist',
  components: {
    OrderControlMnt: () => import('./order-control-mnt'),
    MaterialDataDialog: () => import('@/views/dialog/material-data-dialog'),
    OrderConfigOptionalMnt: () => import('./order-configOptional-mnt'),
    OrderPartTrackMnt: () => import('./order-partTrack-mnt.vue')
  },
  props: {},
  data() {
    return {
      showOrderConfigOptional: false,
      showOrderPartTrack: false,
      showMaterialData: false,
      dialogVisible: false,
      operType: '',
      editData: {},
      chooseData: {},
      tableData1: [],
      tableData2: [],
      tableData3: [],
      plantOptions: [],
      formModel: {
        planNo: '',
        plantNo: '',
        orderId: '',
        materialNo: '',
        orderStatus: '',
        vin: '',
        isDelete: '0'
      },
      columns: [
        { title: '计划编号', key: 'planNo' },
        { title: '订单编号', key: 'orderId' },
        { title: '车辆VIN号', key: 'vin' },
        { title: '订单状态', key: 'orderStatus', clcd: 'order_status_cd' },
        { title: '工厂代码', key: 'plantNo' },
        { title: '工厂名称', key: 'plantNameC' },
        { title: '整车物料号', key: 'materialNo' },
        { title: '物料描述', key: 'materialDesc' },
        { title: '车型', key: 'productTypeKey', clcd: 'key_product_type' },
        { title: '生产类型', key: 'proType', clcd: 'Key_Product_Type' },
        { title: '销售类型', key: 'saleType', clcd: 'Key_Sale_Type' },
        { title: '需求类型', key: 'needType', clcd: 'need_type_cd' },
        { title: 'VIN年份', key: 'vinYear', clcd: 'Key_Vin_ModeYear' },
        { title: '预分配经销商编号', key: 'dealerCode' },
        { title: '计划上线日期', key: 'planStartDate' },
        { title: '计划下线日期', key: 'planEndDate' },
        { title: '实际上线日期', key: 'practicalStartDate' },
        { title: '实际下线日期', key: 'practicalEndDate' },
        { title: '工艺路线代码', key: 'routeNo' },
        { title: '工艺路线名称', key: 'routeName' },
        { title: '上线产线代码', key: 'lineNo' },
        { title: '上线产线名称', key: 'lineNameC' },
        { title: '上线序列号', key: 'sortNum' },
        { title: '创建时间', key: 'createTime' },
        { title: '创建人', key: 'createUsername' },
        { title: '更新次数', key: 'updateNum' },
        { title: '最后修改时间', key: 'lastUpdateTime' },
        { title: '最后修改人', key: 'lastUpdateUsername' }
      ],
      columns1: [
        { title: '装配工位代码', key: 'ulocNo' },
        { title: '配置代码', key: 'configNo' },
        { title: '配置项代码', key: 'configItemNo' },
        { title: '零部件物料编码', key: 'materialItemNo' },
        { title: '零部件物料描述', key: 'materialItemDesc' },
        { title: '创建时间', key: 'createTime' },
        { title: '创建人', key: 'createUsername' },
        { title: '更新次数', key: 'updateNum' },
        { title: '最后修改时间', key: 'lastUpdateTime' },
        { title: '最后修改人', key: 'lastUpdateUsername' }
      ],
      columns2: [
        { title: '追溯工位代码', key: 'ulocNo' },
        { title: '零件追溯件代码', key: 'partTrackNo' },
        { title: '组件号', key: 'groupNumber' },
        { title: '前中后标记', key: 'locationTab', clcd: 'location_tab' },
        { title: '环保件标记', key: 'environmentTag', clcd: 'ind_cd' },
        { title: '对称件标记', key: 'symmetricalPartTab', clcd: 'ind_cd' },
        { title: '创建时间', key: 'createTime' },
        { title: '创建人', key: 'createUsername' },
        { title: '更新次数', key: 'updateNum' },
        { title: '最后修改时间', key: 'lastUpdateTime' },
        { title: '最后修改人', key: 'lastUpdateUsername' }
      ],
      columns3: [
        { title: '工程整车号', key: 'vehicleNo' },
        { title: '识别码', key: 'markCode' },
        { title: '模块代码', key: 'moduleCode' },
        { title: '字段代码', key: 'filedCode' },
        { title: '字段值', key: 'filedValue' },
        { title: 'EW审核信息', key: 'ewAuditInfo' },
        { title: 'MW审核信息', key: 'mwAuditInfo' },
        { title: '创建时间', key: 'createTime' },
        { title: '创建人', key: 'createUsername' },
        { title: '最后修改时间', key: 'lastUpdateTime' },
        { title: '最后修改人', key: 'lastUpdateUsername' }
      ]
    }
  },
  computed: {

  },
  mounted() {
    this.getPlants()
  },
  methods: {
    clearCondition() {
      this.resetObj(this.formModel)
      this.formModel.isDelete = '0'
    },
    queryMaterialData() {
      this.editData.materialTypeKey = 'car'
      this.showMaterialData = true
    },
    queryMaterialDataSuc(data) {
      this.formModel.materialNo = data.materialNo
    },
    handleRowClick(row) {
      if (row) {
        this.chooseData = row
        // 通过订单编号查子表
        this.queryList1()
        this.queryList2()
        this.queryList3()
      } else {
        // 清空选中数据
        this.chooseData = {}
      }
    },
    getPlants() {
      const param = { pageNum: 1, pageSize: 9999 }
      param.isDelete = '0'
      param.status = '1'
      this.get('/tmBasPlant/queryTmBasPlant', param).then(res => {
        this.plantOptions = res.list
      })
    },
    queryList() {
      this.chooseData = {}
      this.tableData1 = []
      this.tableData2 = []
      this.tableData3 = []
      this.$refs.table.query('/tmOfmOrder/queryTmOfmOrder', this.formModel, '', false)
    },
    queryList1() {
      // 订单选配配置查询
      const param = {}
      param.orderId = this.chooseData.orderId
      param.isDelete = '0'
      this.$refs.table1.query('/tmOfmOrder/queryTmOfmImesBom', param, '', false)
    },
    queryList2() {
      // 订单追溯配置
      const param = {}
      param.orderId = this.chooseData.orderId
      param.isDelete = '0'
      this.$refs.table2.query('/tmOfmOrder/queryOrderQasKeyPartTrack', param, '', false)
    },
    queryList3() {
      // 订单电检配置
      const param = {}
      param.orderId = this.chooseData.orderId
      param.isDelete = '0'
      this.$refs.table3.query('/tmOfmOrder/queryTmOrderEcuConfig', param, '', false)
    },
    handleEdit(row) {
      this.dialogVisible = true
      this.operType = 'edit'
      this.editData = row || {}
    },
    // 订单选配修改
    handleEditBom(row) {
      const param = { pageNum: 1, pageSize: 9999 }
      param.isDelete = '0'
      param.orderId = row.orderId
      this.get('/tmOfmOrder/queryTmCarVehicle', param).then(res => {
        if (res.list && res.list.length == 1 && res.list[0].proTime) {
          this.$warn('该订单已有制造时间,不允许修改配置!')
          return false
        } else {
          this.showOrderConfigOptional = true
          this.operType = 'edit'
          this.editData = row || {}
        }
      })
    },
    // 订单选配删除
    handleDeleteBom(row) {
      const param = { pageNum: 1, pageSize: 9999 }
      param.isDelete = '0'
      param.orderId = row.orderId
      this.get('/tmOfmOrder/queryTmCarVehicle', param).then(res => {
        if (res.list && res.list.length == 1 && res.list[0].proTime) {
          this.$warn('该订单已有制造时间,不允许修改配置!')
          return false
        } else {
          this.$sure('确认删除？', _ => {
            this.post('/tmOfmOrder/deleteTmOfmImesBom', { rcrdId: row.rcrdId, operateType: '03' }).then(_ => {
              this.$info('删除成功', this.queryList)
            })
          })
        }
      })
    },
    // 订单追溯修改
    handleEditPartTrack(row) {
      const param = { pageNum: 1, pageSize: 9999 }
      param.isDelete = '0'
      param.orderId = row.orderId
      this.get('/tmOfmOrder/queryTmCarVehicle', param).then(res => {
        if (res.list && res.list.length == 1 && res.list[0].proTime) {
          this.$warn('该订单已有制造时间,不允许修改配置!')
          return false
        } else {
          this.showOrderPartTrack = true
          this.operType = 'edit'
          this.editData = row || {}
        }
      })
    },
    // 订单追溯删除
    handleDeletePartTrack(row) {
      const param = { pageNum: 1, pageSize: 9999 }
      param.isDelete = '0'
      param.orderId = row.orderId
      this.get('/tmOfmOrder/queryTmCarVehicle', param).then(res => {
        if (res.list && res.list.length == 1 && res.list[0].proTime) {
          this.$warn('该订单已有制造时间,不允许修改配置!')
          return false
        } else {
          this.$sure('确认删除？', _ => {
            this.post('/orderQasKeyPartTrack/deleteOrderQasKeyPartTrack', { rcrdId: row.rcrdId, operateType: '03' }).then(_ => {
              this.$info('删除成功', this.queryList)
            })
          })
        }
      })
    }
  }
}
</script>

